package com.seu.clab.farm.controller;

import com.seu.clab.farm.common.CONST;
import com.seu.clab.farm.common.annotation.TokenRequired;
import com.seu.clab.farm.common.annotation.WebResponse;
import com.seu.clab.farm.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@CrossOrigin
@WebResponse
/**
 * 没有二级前缀的接口写这里来，如/log,  /payment
 */
public class UtilController {

    @Autowired
    private PaymentService paymentService;

    @Autowired
    private HttpServletRequest request;

    @TokenRequired
    @PostMapping("/payment")
    public Object setPicUrl(@RequestBody Map<String,String> requestBody){
        String accountId = (String) request.getAttribute(CONST.ACL_ACCOUNTID);
        String url=requestBody.get("url");
        paymentService.setPayPic(url,accountId);
        return null;
    }

    @TokenRequired
    @GetMapping("/payment")
    public Object showPayPic(){
        String url=paymentService.showPayPic();
        return url;
    }
}
